﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace MappitLib {
    public class Tilemap {
        //***********************************************************
        #region Class Defaults
        public static int DefaultTileWidth = 100;
        public static int DefaultTileHeight = 100;
        #endregion
        //***********************************************************
        #region Error Codes
        #endregion
        //***********************************************************
        #region Members
        public static readonly Point InvalidCoord = new Point(-1, -1);
        private Tileset tileset_ = null;
        private int height_ = DefaultTileWidth;
        private int width_ = DefaultTileHeight;
        private Tile[] map_;
        private string filename_ = null;
        #endregion
        //***********************************************************
        #region Properties
        /*! The width of the map, in tiles.
         */
        public int Width {
            get {
                return width_;
            }
            set {
                width_ = value;
            }
        }
        /*! The height of the map, in tiles.
         */
        public int Height {
            get {
                return height_;
            }
            set {
                height_ = value;
            }
        }
        /*! Filename for this tilemap.
         */
        public string Filename {
            get { return filename_; }
            set { filename_ = value; }
        }
        /*! Tileset that this map is associated with.
         */
        public Tileset TileSet {
            get { return tileset_; }
            set { tileset_ = value; }
        }
        #endregion
        //***********************************************************
        #region Methods
        /*! Construction.
         */
        public Tilemap() {
            map_ = new Tile[width_ * height_];
        }
        /*! Retrieve a tile from a given coordinate.
         */
        public Tile GetTile(int x, int y) {
            return map_.ElementAt(y * width_ + x);
        }
        /*! Set a tile value.
         */
        public void SetTile(Tile tile, Point map_coord) {
            map_[map_coord.Y * width_ + map_coord.X] = tile;
        }
        #endregion
        //***********************************************************
    }
}
